/**
 * @file GetContactsHandler.cs
 * @author Zane Mayo
 * @date 6/5/2009
 */

using System;
using System.Collections.Generic;

namespace MxitAPI {
	
	
	public class GetContactsHandler : Handler {
		
		public GetContactsHandler() : base( typeof( GetContactsProtocolMessage ) ) {
		}
		
		protected override void HandleSpecificResponseProtocolMessage( ProtocolMessage message ) {
			GetContactsProtocolMessage getContactsMessage =  message as GetContactsProtocolMessage;
			if ( getContactsMessage == null ) 
				throw new MxitException( "Could not handle response. The message is of the wrong type." );
			
			List<RawContact> rawContacts = getContactsMessage.RawContacts;
			
			// Add each raw Mxit contact to the list of all contacts and get its unque Id
			foreach ( RawContact rawContact in rawContacts ) {
				int contactId = Contacts.Instance.AddContact( rawContact );
				//Console.WriteLine( contactId );
			}
            //Contacts.Instance.DoContactsEvent();
			
		}
		
		
	}
}
